﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LastStand.gameContent;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace LastStand.gameContent.Friendlies
{
    public class Friendly : Sprite
    {
        /// <summary>
        /// identity allows for this unit to be referenced specifically.
        /// </summary>
        private int identity;

        public int GetIdentity { get { return identity; } }
        protected int Identity { set { identity = value; } }

        /// <summary>
        /// creates a random object to see if the unit hits its targeted enemy.
        /// </summary>
        protected Random rand = new Random();

        /// <summary>
        /// Can the pimp slap?
        /// </summary>
        protected Boolean canAttack;
        
        /// <summary>
        /// Can the pimp upgrade his pimp rings?
        /// </summary>
        protected Boolean canRankUp;

        /// <summary>
        /// Array of names the unit can rank up to. 
        /// The unit will always start at Private.
        /// </summary>
		protected string[] rankNames = new string[5] 
            { 
                "Private",
                "Corporal",
                "Lieutenant",
                "Captain",
                "General"
            };

        /// <summary>
        /// This units profeciency level.
        /// </summary>
        protected int rank = 0;

        /// <summary>
        /// Rank name, ie. private, or captain
        /// </summary>
        protected string rankName;
        
        /// <summary>
        /// Whats the pimps reach?
        /// </summary>
        private float attackDistance;

        protected float GetAttackDistance { get { return this.attackDistance; } }
        protected float AttackDistance { set { this.attackDistance = value; } }

        /// <summary>
        /// How hard does this pimp slap?
        /// </summary>
        private float attackPower;

        public float GetAttackPower { get { return this.attackPower; } }
        protected float AttackPower { set { this.attackPower = value; } }

        /// <summary>
        /// How much does this pimps new pimp'n rings cost?
        /// </summary>
        private int rankUpCost;

        protected int GetUpgradeCost { get { return this.rankUpCost; } }
        protected int RankUpCost { set { this.rankUpCost = value; } }

        /// <summary>
        /// How long since the pimp's last slap?
        /// </summary>
        protected float attackTimer = 0.0f;
        
        /// <summary>
        /// How many seconds between attacks?
        /// </summary>
        protected float attackInterval;

        /// <summary>
        /// What is this units accuracy?
        /// </summary>
        private float accuracy;

        protected float GetAccuracy { get { return this.accuracy; } }
        protected float Accuracy { set { this.accuracy = value; } }

        /// <summary>
        /// This method attack is called in the deriving class's update method.
        /// </summary>
        public virtual void Attack(Vector2 dest)
        {
            //sets the unit to a mode in which it cannot attack.
            this.canAttack = false;

            //creates a shot assigned to this unit and a des`tination the shot is going to.
            //Shot shot = new Shot(dest);
        }
        
        /// <summary>
        /// this method will be called by a xaml button interaction.
        /// ----This interaction will be determined later----
        /// </summary>
        public virtual void UpgradeLevel(int newRankUpCost, float newAttackPower, float newAttackInterval, float newAccuracy, float newAttackDistance)
		{
            //ranks integer value is increased by one.
            this.rank++;

            //applies the cost for the next upgrade based
            //on a value sent by the specific unit.
            this.RankUpCost = newRankUpCost;

            //applies an upgraded attack power value.
            this.AttackPower = newAttackPower;

            //applies an upgraded attack speed.
            this.attackInterval = newAttackInterval;

            //applies an upgraded accuracy for more effective shots.
            this.Accuracy = newAccuracy;
		}
    }
}
